#include <iostream>
using namespace std;

#include "lazy_set.h"

bool compare(int i1, int i2)
{
    return i1 < i2;
}

using Less = std::function<bool (int, int)>;

int main()
{
    srand(time(nullptr));
    LazySet<int, Less> lazy_set(compare);
    for (int i = 0; i < 100; ++i) {
        lazy_set.emplace(rand() % 1000);
    }
    lazy_set.emplace(500);
    lazy_set.sort();
    auto pre = lazy_set.begin();
    for (auto iter = pre+1; iter != lazy_set.end(); ++iter) {
        std::cerr << "index:[" << (pre - lazy_set.begin()) << "]" << *pre << ' ' << *iter << endl;
        assert(*pre <= *iter);
        pre = iter;
    }

    auto iter = lazy_set.upper_bound(10000);
    cerr << (iter - lazy_set.begin()) << endl;
    iter = lazy_set.lower_bound(10000);
    cerr << (iter - lazy_set.begin()) << endl;

    iter = lazy_set.lower_bound(500);
    cerr << "found lower 500:" << (iter - lazy_set.begin()) << endl;
    iter = lazy_set.upper_bound(500);
    cerr << "found upper 500:" << (iter - lazy_set.begin()) << endl;


    assert(lazy_set.lower_bound(0) == lazy_set.begin());
    assert(lazy_set.upper_bound(-1) == lazy_set.begin());

    assert(lazy_set.lower_bound(1000) == lazy_set.end());
    assert(lazy_set.upper_bound(1000) == lazy_set.end());
}
